package com.burstly.lib.util.calendar;

import android.content.Context;
import android.content.Intent;
import android.util.SparseArray;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;

abstract class AbstractCalendarEventsHandler
{
  private static final SparseArray<String> DAYS_MAP;
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = AbstractCalendarEventsHandler.class.getSimpleName();
  protected CalendarEventsHandler.IEventsHandlerCallback mCallback;
  protected Context mContext;

  static
  {
    DAYS_MAP = new SparseArray(7);
    DAYS_MAP.put(0, "SU");
    DAYS_MAP.put(1, "MO");
    DAYS_MAP.put(2, "TU");
    DAYS_MAP.put(3, "WE");
    DAYS_MAP.put(4, "TH");
    DAYS_MAP.put(5, "FR");
    DAYS_MAP.put(6, "SA");
  }

  AbstractCalendarEventsHandler(Context paramContext, CalendarEventsHandler.IEventsHandlerCallback paramIEventsHandlerCallback)
  {
    this.mContext = paramContext;
    this.mCallback = paramIEventsHandlerCallback;
  }

  private static void appendArray(String paramString, StringBuilder paramStringBuilder, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject != null) && (paramArrayOfObject.length > 0))
      paramStringBuilder.append(paramString).append(Utils.arrayToString(paramArrayOfObject, ",")).append(";");
  }

  protected static String parseEventRepeatRule(EventRepeatRule paramEventRepeatRule)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    if (paramEventRepeatRule.frequency != null)
    {
      if (!paramEventRepeatRule.frequency.equals("daily"))
        break label93;
      localStringBuilder.append("FREQ=DAILY;");
      setUntilDate(paramEventRepeatRule, localStringBuilder);
    }
    while (true)
    {
      if (paramEventRepeatRule.interval != null)
        localStringBuilder.append("INTERVAL=").append(paramEventRepeatRule.interval).append(";");
      if (paramEventRepeatRule.exceptionDates != null)
        LOG.logWarning(TAG, "exceptionDates not supported", new Object[0]);
      return localStringBuilder.toString();
      label93: if (paramEventRepeatRule.frequency.equals("weekly"))
      {
        localStringBuilder.append("FREQ=WEEKLY;");
        setUntilDate(paramEventRepeatRule, localStringBuilder);
        if ((paramEventRepeatRule.daysInWeek != null) && (paramEventRepeatRule.daysInWeek.length > 0))
        {
          localStringBuilder.append("BYDAY=");
          int i = 0;
          int j = paramEventRepeatRule.daysInWeek.length;
          while (i < j)
          {
            localStringBuilder.append((String)DAYS_MAP.get(paramEventRepeatRule.daysInWeek[i].intValue()));
            if (i + 1 != j)
              localStringBuilder.append(",");
            i++;
          }
          localStringBuilder.append(";");
        }
      }
      else if (paramEventRepeatRule.frequency.equals("monthly"))
      {
        localStringBuilder.append("FREQ=MONTHLY;");
        setUntilDate(paramEventRepeatRule, localStringBuilder);
        appendArray("BYMONTHDAY=", localStringBuilder, paramEventRepeatRule.daysInMonth);
        appendArray("BYWEEKNO=", localStringBuilder, paramEventRepeatRule.weeksInMonth);
      }
      else if (paramEventRepeatRule.frequency.equals("yearly"))
      {
        localStringBuilder.append("FREQ=YEARLY;");
        setUntilDate(paramEventRepeatRule, localStringBuilder);
        appendArray("BYYEARDAY=", localStringBuilder, paramEventRepeatRule.daysInYear);
        appendArray("BYMONTH=", localStringBuilder, paramEventRepeatRule.monthsInYear);
      }
    }
  }

  private static void setUntilDate(EventRepeatRule paramEventRepeatRule, StringBuilder paramStringBuilder)
  {
    if (paramEventRepeatRule.expires != null)
      paramStringBuilder.append("UNTIL=").append(paramEventRepeatRule.expires).append(";");
  }

  protected abstract void populateIntent(Intent paramIntent, CalendarEvent paramCalendarEvent)
    throws Exception;

  final void scheduleEvent(CalendarEvent paramCalendarEvent)
  {
    Intent localIntent = new Intent();
    try
    {
      populateIntent(localIntent, paramCalendarEvent);
      this.mContext.startActivity(localIntent);
      this.mCallback.addedSuccessfully();
      return;
    }
    catch (Exception localException)
    {
      this.mCallback.errorOccured("Can not save an event");
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.util.calendar.AbstractCalendarEventsHandler
 * JD-Core Version:    0.6.2
 */